var BBRDGWS = BBRDGWS || {};

BBRDGWS.getElementsByClassName = BBRDGWS.getElementsByClassName || function (parentElement, class_name, tag, callback) {
	"use strict";
	/*jslint browser: true */
	/*global top: true */
	/* Code below originally taken from http://lawrence.ecorp.net/inet/samples/js-getelementsbyclassnameex.shtml and refactored/modified by Guy Pursey (@ University of Reading) */

	var matchArray = [],
		re = new RegExp("(?:^|\\s)" + class_name + "(?:\\s|$)"),
		docList,
		len;

	tag = tag || "*";
	callback = callback || function (obj) { };
	parentElement = parentElement || document;
	if (typeof parentElement === "string") {
		/* object could be passed instead of Id */
		parentElement = document.getElementById(parentElement);
	}

	/* Get array of tags */ /* could potentially refactor this to one clear line at top of function, with ternary operator, default operator and some parens */
	if (tag === "*") {
	   /* This test is to accommodate IE5 */
		docList = parentElement.all || parentElement.getElementsByTagName(tag);
	} else {
		docList = parentElement.getElementsByTagName(tag);
	}

	/* Create output array */ /* if the above is refactored, we could move this assignment into the declaration at the top too */
	len = docList.length;

	while (len) { /* slightly refactored while-loop to pass JSLint */
		len -= 1;
		if (re.test(docList[len].className)) {
			matchArray[matchArray.length] = docList[len];
			callback(matchArray[matchArray.length - 1]);
		}
	}
	return matchArray.reverse();
}; //eof